package io.renren.common.utils;

import java.util.Random;

/**
 * @author hardy(qinwei)
 * @date 14:20 2020/8/28
 * @description 随机生成用户名
 */
public class RandomString {
    public static void main(String[] args) {
        String randomString = getRandomString();
        System.out.println(randomString);
        String fourRandomString = getFourRandomString();
        System.out.println(fourRandomString);
    }
    // 生成随机用户名
    public static String getRandomString(){
        int length =10;
        String title = "Zhupinhang_";
        String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random random=new Random();
        StringBuffer sb=new StringBuffer();
        for(int i=0;i<length;i++){
            int number=random.nextInt(62);
            sb.append(str.charAt(number));
        }
        return title+sb.toString();
    }
    // 生成4位随机数
    public static String getFourRandomString(){
        int length =4;
        String str="0123456789";
        Random random=new Random();
        StringBuffer sb=new StringBuffer();
        for(int i=0;i<length;i++){
            int number=random.nextInt(9);
            sb.append(str.charAt(number));
        }
        return sb.toString();
    }

    // 生成6位随机数
    public static String getSixRandomString(){
        int length =6;
        String str="0123456789";
        Random random=new Random();
        StringBuffer sb=new StringBuffer();
        for(int i=0;i<length;i++){
            int number=random.nextInt(9);
            sb.append(str.charAt(number));
        }
        return sb.toString();
    }
}
